#include "config.h"
#include "bullet.h"
#include "QMainWindow"
bullet::bullet()
{
    m_bullet1.load(BULLET1_PATH);

    m_x=GAME_WINDTH*0.5-m_bullet1.width()*0.5;
     m_y=GAME_HEIGHT;

    m_free=true;

     m_speed=BULLET_SPEED;
    //普通子弹的sheji
    m_rect.setWidth(m_bullet1.width());
    m_rect.setHeight(m_bullet1.height());
    m_rect.moveTo(m_x,m_y);
    // //
    m_bullet2.load(BULLET1_PATH);
    m_xa=GAME_WINDTH*0.5-m_bullet2.width()*0.5;
    m_ya=GAME_HEIGHT+m_bullet2.height();
    m_freea=true;
    m_speed=BULLET_SPEED;
    m_recta.setWidth(m_bullet2.width());
    m_recta.setHeight(m_bullet2.height());
    m_recta.moveTo(m_xa,m_yb);
    //  //
    m_bullet3.load(BULLET1_PATH);
    m_xb=GAME_WINDTH*0.5-m_bullet3.width()*0.5;
    m_yb=GAME_HEIGHT+m_bullet3.height();
    m_freeb=true;
    m_speed=BULLET_SPEED;
    m_rectb.setWidth(m_bullet3.width());
    m_rectb.setHeight(m_bullet3.height());
    m_rectb.moveTo(m_xb,m_yb);


}
void  bullet::updatePosition()
{
    if(m_free&&m_freea&&m_freeb)//判断子弹是否空闲
    {
        return;

    }
    if((!m_free&&m_freea&&m_freeb)||(!m_free&&!m_freea&&m_freeb)||(!m_free&&!m_freea&&!m_freeb)||(!m_free&&m_freea&&!m_freeb))
    {
        m_y-=m_speed;
    m_rect.moveTo(m_x,m_y);

    if(m_y<=-m_rect.height())
    {
        m_free=true;
    }
    //std::cout<<*this->parent();
    }
    if((!m_free&&!m_freea&&!m_freeb)||(!m_free&&!m_freea&&m_freeb)||(m_free&&!m_freea&&m_freeb)||(m_free&&!m_freea&&!m_freeb))
    {

    m_ya-=m_speed;
    m_recta.moveTo(m_xa,m_ya);

    if(m_ya<=-m_rect.height())
    {
        m_freea=true;
    }
    }

    if((!m_free&&!m_freea&&!m_freeb)||(m_free&&!m_freea&&!m_freeb)||(m_free&&m_freea&&!m_freeb)||(!m_free&&m_freea&&!m_freeb))
    {

    m_yb-=m_speed;
    m_rectb.moveTo(m_xb,m_yb);

    if(m_yb<=-m_rectb.height())
    {
        m_freeb=true;
    }
    }
}






